<!DOCTYPE html>
<html class="car-loan">

	<head>
		<meta charset="UTF-8">
		<title>我要报单</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../Public/css/Home/mui.css" />
		<link rel="stylesheet" href="../Public/css/Home/public.css" />
		<link rel="stylesheet" href="../Public/css/Home/mui.picker.css" />
		<link rel="stylesheet" href="../Public/css/Home/mui.poppicker.css" />
		<link rel="stylesheet" href="../Public/css/Home/post-form.css" />
	</head>

	<body>
		<!--header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">我要报单</h1>
		</header-->
		<div class="mui-content">
			<ul class="input-group">
				<li class="input-row layout-center pt10 pb10">
					<label>报单金额</label>
					<div class="flex-item1">
						<input id="money" class="tr" type="tel" placeholder="请输入报单金额"  oninput="updateFee()"  />
					</div>
				</li>
				<li class="input-row layout-center">
					<label>姓名</label>
					<div class="flex-item1">
						<input id="realName" class="tr" type="text" name="realName" placeholder="请输入姓名"/>
					</div>
				</li>
				<li class="input-row layout-center mb10">
					<label>手机号</label>
                                        <div class="flex-item1">
                                            <input id="mobile" class="tr" type="tel" name="mobile" placeholder="请输入手机号" />
                                        </div>
				</li>
				<li class="input-row layout-center mb10">
					<label>平台服务费</label>
                                        <div class="flex-item1" id="fee_amount">
                                            0
                                        </div>
				</li>
				
			</ul>
		</div>

		<div class="car-foot">
                    <div class="text"><img class="iconfont" src="../Public/img/icon-security.png" />报单严格保护你的信息安全，未经你允许不会对外泄露</div>
			<div class="btn">
				<button id="sendBtn" class="mui-btn mui-btn-block send-btn" type="button">确认并提交</button>
			</div>
		</div>
	</body>
	<script src="../Public/js/Home/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../Public/js/Home/mui.js" type="text/javascript" charset="utf-8"></script>
	<script src="../Public/js/Home/common.js" type="text/javascript" charset="utf-8"></script>
	<script src="../Public/js/Home/mui.picker.js"></script>
	<script src="../Public/js/Home/mui.poppicker.js"></script>
	<script>
		function updateFee(){
			var money = document.getElementById('money').value;
			if(!money) {
				alert("请输入报单金额!");
				return false;
			}
			var fee = money*0.1;
			if(fee < 1){
				fee = 1;
			}
			document.getElementById("fee_amount").innerHTML = fee;
			
			if(parseInt(userInfo.integral) < parseInt(money) + fee){
				alert("资金不足，当前账户可用："+userInfo.integral);
			}
		}
		var userInfo,type = 3;
                
                $(function(){
                    userInfo = JSON.parse(common.getLocVal('userData'));
                    console.log(userInfo.integral);
                })
		document.getElementById("sendBtn").addEventListener('tap', function() {
			var money = document.getElementById('money').value;
			if(!money) {
				common.alert("提示", "请输入报单金额!");
				return false;
			}
			var fee = money*0.1;
			if(fee < 1){
				fee = 1;
			}
                        if(parseFloat(userInfo.integral) < parseInt(money) + fee){
                            alert("提示", "资金不足!");
                            return false;
                        }
			var real_name = document.getElementById("realName").value;
			if(!real_name) {
				common.alert("提示", "请输入您的真实姓名!");
				return false;
			}
                        var mobile = document.getElementById("mobile").value;
                        if(common.isTelphone(mobile) === false){
                            common.alert("提示", "请输入正确的手机号!");
				return false;
                        }
			var params = {
				url: 'Baodan/save',
				data: {
                                        user_id : common.getLocVal("userId"),
					money: parseInt(money),
					real_name: real_name,
					mobile : mobile,
				}
			}
			common.loading("正在提交...请稍后...");
			common.JsonPost(params, function(data) {
				common.closeLoading();
                                userInfo.integral = data.integral;
                                userInfo.return_integral = data.return_integral;
                                common.setLocVal("userData",JSON.stringify(userInfo));
				common.alert("提示", "提交成功!",function(){
                                    common.reload();
                                });
				
                                //扣除用户缓存中的积分
                                
			})
		});
	</script>

</html>